const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  mode: "development",
  entry: './src/index.js',
  output: {
    path: resolve(__dirname, 'dist'),
    filename: "[name].js"
  },
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: [
                  'postcss-preset-env'
                ]
              }
            }
          },
          'sass-loader',
        ]
      },
      {
        test: /\.tpl$/,
        loader: 'ejs-loader'
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: "导航栏",
      template: resolve(__dirname, 'public/index.html')
    }),
    new MiniCssExtractPlugin({
      filename: 'css/[name].css',
      chunkFilename:"css/[name].css"
    })
  ],
  devServer: {
    hot: true,
    port: 8090
  }
}
